﻿function AzureOnlineBlobDeleteView(context) {

    var self = this;
    
    var dispatcher = $({});

    var spinner = new SpinnerModel();

    var container = ko.observable(null);

    var blob = ko.observable(null);

    var blobs = context.blobs.blobs;

    function remove() {
        var cnt = container();
        var blb = blob();
        var blobName = blb.name();
        var api = context.api();
        spinner.enter();
        api.blob.deleteBlob({
            container: cnt,
            blob: blobName,
            success: function () {
                spinner.leave();
                blobs.remove(blb);
                dispatcher.trigger('success');
            },
            error: function() {
                spinner.leave();
            }
        });
    }

    function addOnSuccess(handler) {
        dispatcher.bind('success', handler);
    };

    function init(blb) {
        container(context.blobs.container());
        blob(blb);
    }

    self.spinner = spinner;
    self.container = container;
    self.blob = blob;
    self.init = init;
    self.remove = remove;
    self.addOnSuccess = addOnSuccess;
    
}